package com.ruoyi.users.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.users.domain.AddMyfavorite;
import com.ruoyi.users.service.IAddMyfavoriteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收藏Controller
 * 
 * @author zbz
 * @date 2024-05-19
 */
@RestController
@RequestMapping("/users/myfavorite")
public class AddMyfavoriteController extends BaseController
{
    @Autowired
    private IAddMyfavoriteService addMyfavoriteService;

    /**
     * 查询收藏列表
     */
    @PreAuthorize("@ss.hasPermi('users:myfavorite:list')")
    @GetMapping("/list")
    public TableDataInfo list(AddMyfavorite addMyfavorite)
    {
        startPage();
        List<AddMyfavorite> list = addMyfavoriteService.selectAddMyfavoriteList(addMyfavorite);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @PreAuthorize("@ss.hasPermi('users:myfavorite:export')")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AddMyfavorite addMyfavorite)
    {
        List<AddMyfavorite> list = addMyfavoriteService.selectAddMyfavoriteList(addMyfavorite);
        ExcelUtil<AddMyfavorite> util = new ExcelUtil<AddMyfavorite>(AddMyfavorite.class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('users:myfavorite:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(addMyfavoriteService.selectAddMyfavoriteById(id));
    }

    /**
     * 新增收藏
     */
    @PreAuthorize("@ss.hasPermi('users:myfavorite:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddMyfavorite addMyfavorite)
    {
        return toAjax(addMyfavoriteService.insertAddMyfavorite(addMyfavorite));
    }

    /**
     * 修改收藏
     */
    @PreAuthorize("@ss.hasPermi('users:myfavorite:edit')")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddMyfavorite addMyfavorite)
    {
        return toAjax(addMyfavoriteService.updateAddMyfavorite(addMyfavorite));
    }

    /**
     * 删除收藏
     */
    @PreAuthorize("@ss.hasPermi('users:myfavorite:remove')")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(addMyfavoriteService.deleteAddMyfavoriteByIds(ids));
    }
}
